//
//  CALoginView.m
//  LNH
//
//  Created by twentylx on 2018/2/4.
//  Copyright © 2018年 twentylx. All rights reserved.
//

#import "CALoginView.h"

@implementation CALoginView

/**
 为视图绑定 viewModel
 
 @param viewModel 要绑定的ViewModel
 @param params 额外参数
 */
- (void)bindViewModel:(id <LMViewProtocol>)viewModel withParams:(NSDictionary *)params {
    
}

/**
 初始化额外数据
 */
- (void)lm_initializeForView {
    
}

/**
 初始化视图
 */
- (void)lm_createViewForView {
    [self setNeedsUpdateConstraints];
    
    [self addSubview:self.inputView];
    [self.inputView addSubview:self.phoneTextField];
    [self.inputView addSubview:self.msgButton];
    [self.inputView addSubview:self.lineView];
    [self.inputView addSubview:self.verifyCodeTextField];
    [self.inputView addSubview:self.line1View];
    [self.inputView addSubview:self.tjmTextField];
    [self.inputView addSubview:self.scanButton];
}

#pragma mark layout
- (void)updateConstraints {
    [super updateConstraints];
    
    [_inputView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    [_phoneTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.equalTo(self.inputView);
        make.top.equalTo(self.inputView);
        make.height.mas_equalTo(44);
    }];
    
    [_msgButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.phoneTextField);
        make.right.equalTo(self.inputView).offset(-20);
        make.height.mas_equalTo(35);
        make.width.mas_equalTo(120);
    }];
    
    [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.equalTo(self.inputView);
        make.top.equalTo(self.phoneTextField.mas_bottom);
        make.height.mas_equalTo(ONE_PIXEL);
    }];
    
    [_verifyCodeTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.equalTo(self.inputView);
        make.top.equalTo(self.lineView.mas_bottom);
        make.height.mas_equalTo(44);
    }];
    
    [_line1View mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.equalTo(self.inputView);
        make.top.equalTo(self.verifyCodeTextField.mas_bottom);
        make.height.mas_equalTo(ONE_PIXEL);
    }];
    
    [_tjmTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.equalTo(self.inputView);
        make.top.equalTo(self.line1View);
        make.height.mas_equalTo(44);
    }];
    
    [_scanButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.tjmTextField);
        make.right.equalTo(self.inputView).offset(-20);
        make.height.mas_equalTo(30);
        make.width.mas_equalTo(30);
    }];
}

#pragma mark get & set
- (UIView *)inputView {
    if (!_inputView) {
        _inputView = [UIView new];
        _inputView.backgroundColor = [UIColor whiteColor];
    }
    return _inputView;
}

- (UITextField *)phoneTextField {
    if (!_phoneTextField) {
        _phoneTextField = [UITextField new];
        _phoneTextField.placeholder = @"输入手机号码";
        _phoneTextField.leftView = [[UIView alloc] initWithFrame:(CGRect){0, 0, 20, 20}];
        _phoneTextField.leftViewMode = UITextFieldViewModeAlways;
        _phoneTextField.keyboardType = UIKeyboardTypePhonePad;
    }
    return _phoneTextField;
}

- (UIButton *)msgButton {
    if (!_msgButton) {
        _msgButton = [UIButton new];
        [_msgButton setTitle:@"获取验证码" forState:UIControlStateNormal];
        _msgButton.backgroundColor = RGBCOLOR(255, 61, 0);
        _msgButton.titleLabel.font = [UIFont systemFontOfSize:16];
        _msgButton.layer.cornerRadius = 5;
    }
    return _msgButton;
}

- (UIView *)lineView {
    if (!_lineView) {
        _lineView = [UIView new];
        _lineView.backgroundColor = RGBCOLOR(241, 241, 241);
    }
    return _lineView;
}

- (UITextField *)verifyCodeTextField {
    if (!_verifyCodeTextField) {
        _verifyCodeTextField = [UITextField new];
        _verifyCodeTextField.placeholder = @"验证码";
        _verifyCodeTextField.leftView = [[UIView alloc] initWithFrame:(CGRect){0, 0, 20, 20}];
        _verifyCodeTextField.leftViewMode = UITextFieldViewModeAlways;
        _verifyCodeTextField.keyboardType = UIKeyboardTypeNumberPad;
    }
    return _verifyCodeTextField;
}

- (UIView *)line1View {
    if (!_line1View) {
        _line1View = [UIView new];
        _line1View.backgroundColor = RGBCOLOR(241, 241, 241);
    }
    return _line1View;
}

- (UITextField *)tjmTextField {
    if (!_tjmTextField) {
        _tjmTextField = [UITextField new];
        _tjmTextField.placeholder = @"推荐码";
        _tjmTextField.leftView = [[UIView alloc] initWithFrame:(CGRect){0, 0, 20, 20}];
        _tjmTextField.leftViewMode = UITextFieldViewModeAlways;
    }
    return _tjmTextField;
}

- (UIButton *)scanButton {
    if (!_scanButton) {
        _scanButton = [UIButton new];
//        [_scanButton setTitle:@"扫描" forState:UIControlStateNormal];
        [_scanButton setImage:LMImageNamed(@"scan") forState:UIControlStateNormal];
        _scanButton.titleLabel.font = [UIFont systemFontOfSize:14];
    }
    return _scanButton;
}
@end
